//
//  ByApiNews.m
//  recordworktool_ios
//
//  Created by mc on 2018/4/11.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByApiNews.h"

@implementation ByApiNews

+ (void)messageUnreadCount:(ByNetModel *)model
                   success:(void(^)(ByNetBaseResult *result))success
                   failure:(void(^)(ByNetBaseResult *result))failure{
    
    
    NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
    if (model.uid){
        [dictionary setObject:model.uid forKey:@"uid"];
    }
    static NSString *apiType = @"By_Message_unreadCount";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
    
    
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeString
     apiVerson:apiVersion
        params:dictionary
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
           
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = @"添加成功";
           result.data = responseObject;
           result.notify_id = notifyID;
           if(success){
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = error.code;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure){
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
           
       }];
    
    
}

//消息详情接口

+ (void)messageInfo:(ByNetModel *)model
            success:(void(^)(ByNetBaseResult *result))success
            failure:(void(^)(ByNetBaseResult *result))failure{
    NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
    if (model.uid) {
        [dictionary setObject:model.uid forKey:@"uid"];
    }
    if (model.ID) {
        [dictionary setObject:model.ID forKey:@"id"];
    }
    static NSString *apiType = @"By_Message_info";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
    
    
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeDictionary
     apiVerson:apiVersion
        params:dictionary
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
           NSLog(@"消息详情页 responseObject%@", responseObject);
           ByNetModel *netModel = [[ByNetModel alloc] initContentWithDic:responseObject];
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = @"添加成功";
           result.data = netModel;
           result.notify_id = notifyID;
           if(success){
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = error.code;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure){
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
           
       }];
    
    
    
}
+ (void)JgbRecordInfo:(ByNetModel *)model
              success:(void(^)(ByNetBaseResult *result))success
              failure:(void(^)(ByNetBaseResult *result))failure{
    
    
    NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
    if (model.item_id) {
        [dictionary setObject:model.item_id forKey:@"id"];
    }
    static NSString *apiType = @"By_JgbRecord_info";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
    
    
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeDictionary
     apiVerson:apiVersion
        params:dictionary
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
           NSLog(@"消息详情页 responseObject%@", responseObject);
           ByNetModel *netModel = [[ByNetModel alloc] initContentWithDic:responseObject];
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = @"添加成功";
           result.data = netModel;
           result.notify_id = notifyID;
           if(success){
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = error.code;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure){
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
           
       }];
    
}

//消息删除
+ (void)messageDel:(ByNetModel *)model
           success:(void(^)(ByNetBaseResult *result))success
           failure:(void(^)(ByNetBaseResult *result))failure{
    
    NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
    if (model.uid){
        [dictionary setObject:model.uid forKey:@"uid"];
    }
    if (model.ID) {
        [dictionary setObject:model.ID forKey:@"id"];
    }
    static NSString *apiType = @"By_Message_del";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeString
     apiVerson:apiVersion
        params:dictionary
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = @"添加成功";
           result.data = responseObject;
           result.notify_id = notifyID;
           if(success){
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = error.code;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure){
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
           
       }];
    
}






@end
